package com.weme.common.arouter

import android.app.Activity
import android.content.Context
import android.os.Bundle
import android.support.v4.media.session.MediaSessionCompat.KEY_TOKEN
import android.util.Log
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import com.alibaba.android.arouter.facade.Postcard
import com.alibaba.android.arouter.facade.callback.NavigationCallback
import com.alibaba.android.arouter.launcher.ARouter
import com.osom.proto.message.Brocast
import com.weme.common.util.UtilsApp
import com.weme.common.util.showToast
import dev.kratos.api.user_server.v1.Users

object ARouterHelper {



    fun getTargetFragment(path: String): Fragment? {
        return ARouter.getInstance().build(path).navigation() as Fragment?
    }
    fun navigateToActivity(context: Context,pathName:String) {
        ARouter.getInstance().build(pathName).navigation(context)
    }

    const val KEY_ANCHOR_BEAN = "anchorBean"
    const val KEY_LIVE_TIME = "live_time"
    const val KEY_CHANNEL_NAME = "channelName"
    fun navigateToLiveEvaluateActivity(context: Context,channelName:String,time:Long, bean :Users){
        val params = Bundle()
        params.putSerializable(KEY_ANCHOR_BEAN, bean)
        val postcard = ARouter.getInstance().build(ARouterPaths.LIVE_EVALVATE_ACTIVITY)
        params.let { postcard.with(params) }
        params.putString(KEY_CHANNEL_NAME,channelName)
        params.putLong(KEY_LIVE_TIME,time)
        postcard.navigation(context)
    }


    const val KEY_ROOM_BEAN = "roomBean"
    fun navigateToLiveRoomActivity(context: Context, bean :LiveRoomBean){
        val params = Bundle()
        params.putSerializable(KEY_ROOM_BEAN, bean)
        val postcard = ARouter.getInstance().build(ARouterPaths.LIVE_ROOM_ACTIVITY)
        params.let { postcard.with(params) }
        postcard.navigation(context)
    }
    const val KEY_FOLLWING_INDEX = "index"
    fun navigateToFollwingActivity(context: Context, index :Int=0){
        val params = Bundle()
        params.putInt(KEY_FOLLWING_INDEX, index)
        val postcard = ARouter.getInstance().build(ARouterPaths.MINE_FOLLWING_ACTIVITY)
        params.let { postcard.with(params) }
        postcard.navigation(context)
    }

    fun navigateToActivity(context: Context, pathName: String, params: Bundle?) {
        val postcard = ARouter.getInstance().build(pathName)
        params?.let { postcard.with(params) }
        postcard.navigation(context)
    }

    const val KEY_USER_ID = "userID"
    fun navigateToUserInfoActivity(context: Context, userId :Long=0L){
        val params = Bundle()
        params.putLong(KEY_USER_ID, userId)
        val postcard = ARouter.getInstance().build(ARouterPaths.MINE_USER_INFO_ACTIVITY)
        params.let { postcard.with(params) }
        postcard.navigation(context)
    }

    fun navigateToUserInfoActivity(context: FragmentActivity, userId :Long=0L){
        val params = Bundle()
        params.putLong(KEY_USER_ID, userId)
        val postcard = ARouter.getInstance().build(ARouterPaths.MINE_USER_INFO_ACTIVITY)
        params.let { postcard.with(params) }
        postcard.navigation(context,100)
    }

//    const val KEY_USER = "user"
//    fun navigateToUserInfoActivity(context: Context, user: Users) {
//        val params = Bundle()
//        params.putSerializable(KEY_USER, user) // 或使用 Parcelable
//        val postcard = ARouter.getInstance().build(ARouterPaths.MINE_USER_INFO_ACTIVITY)
//        params.let { postcard.with(params) }
//        postcard.navigation(context)
//    }



    const val KEY_CONVERSATION_ID = "conversationId"
    const val KEY_NAME = "name"
    const val KEY_COUNTRY = "country"
    const val KEY_HEAD = "head"


    const val KEY_USER = "user"
    fun navigateToChatActivity(context: Context, user: Users) {
//        if (user.isBlack == 1) {
//            context.showToast(context.getString(com.example.resources.R.string.block_you))
//            return
//        }
        val params = Bundle()

        params.putSerializable(KEY_USER,user)
        val postcard = ARouter.getInstance().build(ARouterPaths.CHAT_ACTIVITY)
        params.let { postcard.with(params) }
        postcard.navigation(context)
    }

    fun navigateToActivityWithResult(
        context: Context,
        pathName: String,
        requestCode: Int,

    ) {

        ARouter.getInstance().build(pathName).navigation(context as Activity, requestCode)
    }

    // ARouterCallback用于处理ARouter回调


//    fun navigateToAnotherActivity(context: Context, param1: String, param2: Int) {
//        ARouter.getInstance()
//            .build(ARouterPaths.ANOTHER_ACTIVITY)
//            .withString("param1", param1)
//            .withInt("param2", param2)
//            .navigation(context)
//    }

    // 可以继续添加其他跳转方法
}
